﻿using System.IO;
using System.Net.Http;
using CkSoftware.GroupMe.Sdk.Core;
using CkSoftware.GroupMe.Sdk.Images.Dao;

namespace CkSoftware.GroupMe.Sdk.Images.Commands
{
	/// <summary>
	/// Upload picture command (GroupMe documentation: <see href="https://dev.groupme.com/docs/image_service#pictures_pictures" />).
	/// </summary>
	public class UploadPictureCommand : IWebApiCommand<UploadPictureResponse>
	{
		private readonly IWebApiCommandParameters _parameters;

		/// <summary>
		/// Instantiate a new <see cref="UploadPictureCommand" /> object by using a url which will be downloaded first.
		/// </summary>
		/// <param name="pictureUrl">The picture url to first download via web.</param>
		/// <param name="name">The name of the picture. This will be used by the upload content-processing for naming a given HTTP content.</param>
		/// <param name="fileName">The filename of the picture.</param>
		public UploadPictureCommand(string pictureUrl, string name, string fileName)
		{
			_parameters = new FileUploadWebApiCommandParameter(pictureUrl, name, fileName);
		}

		/// <summary>
		/// Instantiate a new <see cref="UploadPictureCommand" /> object by using a input stream of an image.
		/// </summary>
		/// <param name="pictureStream">The stream of the image.</param>
		/// <param name="name">The name of the picture. This will be used by the content-processing for naming a given HTTP content.</param>
		/// <param name="fileName">The filename of the picture.</param>
		public UploadPictureCommand(Stream pictureStream, string name, string fileName)
		{
			_parameters = new FileUploadWebApiCommandParameter(pictureStream, name, fileName);
		}

		/// <summary>
		/// The name of the command to be executed.
		/// </summary>
		public string CommandName
		{
			get { return "pictures"; }
		}

		/// <summary>
		/// The http method to execute this command.
		/// </summary>
		public HttpMethod HttpMethod
		{
			get { return HttpMethod.Post; }
		}

		/// <summary>
		/// The parameters which should be used on command execution.
		/// </summary>
		public IWebApiCommandParameters Parameters
		{
			get { return _parameters; }
		}

		/// <summary>
		/// Defines if the command is executed once.
		/// </summary>
		public bool CommandExecuted { get; set; }
	}
}